package com.example.demo.judge.main;

import com.example.demo.judge.entity.LanguageVO;
import com.example.demo.judge.entity.RequestHelper;
import com.example.demo.judge.entity.SubmissionVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Component
public class JudgeService {
    @Autowired
    RestTemplate restTemplate;

    public List<LanguageVO> getLanguageList() {
        LanguageVO[] languageArray = restTemplate.exchange(RequestHelper.GET_LANGUAGES, HttpMethod.GET, RequestHelper.getHttpEntity(null), LanguageVO[].class).getBody();
        List<LanguageVO> list = new ArrayList<LanguageVO>(Arrays.asList(languageArray));
        return list;
    }

    public SubmissionVO judgeCode(SubmissionVO submissionVO) {
        return restTemplate.exchange(RequestHelper.POST_SUBMISSIONS, HttpMethod.POST, RequestHelper.getHttpEntity(submissionVO), SubmissionVO.class).getBody();
    }
}
